<script setup lang="ts">
import ItemReceiveEdit from '../item-receive/edit-single/components/item-receive-edit.vue';
import { onMounted, onBeforeUnmount } from 'vue';
import { state } from '../submit-success/state';
import { reLaunch, getCurrentInstance } from '@tarojs/taro';

/**
 * @description 当前路由信息
 */
const params = getCurrentInstance().router?.params as unknown as {
  title?: string;
  templateCodeList?: string;
};

onMounted(() => {
  state.from = 'item-receive-edit-single';
});
onBeforeUnmount(() => (state.from = ''));
</script>

<template>
  <view class="item-receive-edit-single app-page--1">
    <app-navbar :title="params.title ? decodeURI(params.title) : '物品领用'" />
    <nut-tabs
      model-value="edit"
      class="item-receive-edit-single__tabs"
      @click="
        ({ paneKey }) => {
          if (paneKey === 'record') {
            reLaunch({
              url: `/pages/approve/record/index?from=item_receive_single&title=${params.title}&templateCodeList=${params.templateCodeList}`,
            });
          }
        }
      "
    >
      <nut-tab-pane title="发起申请" pane-key="edit" />
      <nut-tab-pane title="申请记录" pane-key="record" />
    </nut-tabs>
    <item-receive-edit />
  </view>
</template>
<style lang="scss">
.item-receive-edit-single {
  &__tabs {
    .nut-tabs {
      &__content {
        display: none;
      }
    }
  }
}
</style>
